<?php

namespace App\Admin\Forms;

use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\Models\GoldRound;

class GoldStatisticsForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '风爆统计';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request)
    {
        admin_success('查询成功');
        
        return redirect('/admin/gold-statistics?start='.$request->start."&end=".$request->end."&gold_round_id=".$request->gold_round_id."&min=".$request->min."&max=".$request->max,);
    }

    /**
     * Build a form here.
     */
    public function form()
    {

       $arr = GoldRound::all()->pluck('title', 'id')->toArray();
        array_unshift($arr,'全部');
        $this->select('gold_round_id', '风暴场次')
            ->options($arr);
        $this->dateRange('start','end','查询时间范围');
        $this->currency('min', '最小金额')->symbol('￥');
        $this->currency('max', '最大金额')->symbol('￥');
        $this->disableReset();
    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        return [
            'gold_round_id' => !empty(request('gold_round_id')) ? request('gold_round_id') : 0,
            'start' => !empty(request('start')) ? request('start') : Carbon::today(),
            'end' => !empty(request('end')) ? request('end') : Carbon::tomorrow(),
            'min' => !empty(request('min')) ? request('min') : 0,
            'max' => !empty(request('max')) ? request('max') : 1000,
        ];
    }
}
